package fileProcessing;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

public class ProjectDirectories {
	protected static String windowsCurrentUser = getWindowUsername();
	protected static String projectDirectory = "C:\\Users\\"+windowsCurrentUser+"\\Documents\\WVU PII Parser\\Working Files";
	public static String preprocessingDir = projectDirectory+"\\Preprocessing";
	public static String dataFileDir = projectDirectory+"\\Data Files";
	public static String outputFileDir = "C:\\Users\\"+windowsCurrentUser+"\\Desktop\\PII Parsing Output Files";
	public static String auditFileDir = projectDirectory+"\\Audit";
	protected String [] subdirectories = {preprocessingDir,dataFileDir,outputFileDir,auditFileDir};
	
	public static String getWindowUsername(){
		String userName = System.getProperty("user.name");
		return userName;
		}
	
	public void buildProjectDirs(){
		if(!new File(projectDirectory).exists())
			createNewDirectory(projectDirectory);
		for(String s : subdirectories){
			if(!new File(s).exists())
				createNewDirectory(s);
		}
		int index = 0;
		Date currentDate = new Date();
		SimpleDateFormat currentDateFormat = new SimpleDateFormat("MMM,dd yyyy");
		SimpleDateFormat h = new SimpleDateFormat("HH");
		SimpleDateFormat m = new SimpleDateFormat("mm");
		SimpleDateFormat s = new SimpleDateFormat("ss");
		String time = (h.format(currentDate)+"h"+m.format(currentDate)+"m"+s.format(currentDate)+"s");
		int sessionCount=1;
		for(String s_currDate : subdirectories){
			String s_currTime;
			s_currDate += ("\\"+currentDateFormat.format(currentDate));
			s_currTime = (s_currDate+"\\"); 
			if(!new File(s_currDate).exists()){
				createNewDirectory(s_currDate);
				s_currTime = s_currTime+("Session "+sessionCount+" (time begun_"+time+")");
			}
			else{
				sessionCount = 1+(new File(s_currDate).list()).length;
				s_currTime = s_currTime+("Session "+sessionCount+" (time begun_"+time+")");
			}
			if(!new File(s_currTime).exists()){
				createNewDirectory(s_currTime);
			}
				
			 if(index == 0)
				 preprocessingDir = s_currTime;
			 else if(index == 1)
				 dataFileDir = s_currTime;
			 else if(index == 2)
				 outputFileDir = s_currTime;
			 else if(index == 3)
				 auditFileDir = s_currTime;
			index++;
		}
	}
	
	public boolean createNewDirectory(String directoryName)
	{
	  return new File(directoryName).mkdir();
	}
	
}
